﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace UIT.Controls.Data
{
    public class SelectableItemsControl : ItemsControl
    {

        public object SelectedItem
        {
            get
            {
                if (selectedWrapper != null)
                    return selectedWrapper.Item;
                return null;
            }
            set
            {
                SelectedWrapper = Wrappers.FirstOrDefault(wrapper => wrapper.Item == value);
            }
        }

        public IControl SelectedView
        {
            get
            {
                if (selectedWrapper != null)
                    return selectedWrapper.View;
                return null;
            }
            set
            {
                SelectedWrapper = Wrappers.FirstOrDefault(wrapper => wrapper.View.Child == value);
            }
        }

        private ItemWrapper selectedWrapper;

        public ItemWrapper SelectedWrapper
        {
            get { return selectedWrapper; }
            set
            {
                selectedWrapper = value;
                OnPropertyChanged("SelectedWrapper");
                OnPropertyChanged("SelectedItem");
                OnPropertyChanged("SelectedView");
            }
        }


    }
}
